<?php
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/

require_once(CLASS_USERADMIN);

if (!$BigDaddy->IsUserAllowedByAction("view-user-admin"))
{
    header ("Location: /");
    exit;
}

$UserAdmin = new UserAdmin;

$App->sTitle = "User Administration";
$App->sHome = "/user/";

$App->AddOptionHeader('options', 'Options');
$App->AddOption('viewall', 'View All Users', 0, "{$_SERVER["PHP_SELF"]}", 'options');
$App->AddOption('add', 'Add New User', 0, "{$_SERVER["PHP_SELF"]}?action=addnewuser", 'options');


switch($_REQUEST["action"])
{
    case "editusertodb":
    
        $sUsername = $FormInput->ProcessInput($_POST["username"], "ONLY_ALPHA,DB_SANITIZE_STRING");
        $aInfo["firstname"] = $FormInput->ProcessInput($_POST["firstname"], "DB_SANITIZE_STRING");
        $aInfo["lastname"] = $FormInput->ProcessInput($_POST["lastname"], "DB_SANITIZE_STRING");
        $aInfo["position"] = $FormInput->ProcessInput($_POST["position"], "DB_SANITIZE_STRING");
        $aInfo["location"] = $FormInput->ProcessInput($_POST["location"], "DB_SANITIZE_STRING");
        
        $sMsg = $UserAdmin->SetUser($aInfo, $sUsername);
        
        $_SESSION["sUserAdminMsg"] = $sMsg;
    
        header("Location: ".$_SERVER["PHP_SELF"]);
        exit;
    
        break;
    case "edituser":
        $pageParams["include"]="form_useraccount.inc";
        $pageParams["title"] = "Edit User Account";
        
        $aUserInfo = $UserAdmin->GetUserInfoByUsername($_REQUEST["username"]);
        
        $bIsEdit = true;
        break;
    case "addusertodb":
        
        $sUsername = $FormInput->ProcessInput($_POST["username"], "ONLY_ALPHA,DB_SANITIZE_STRING");
        $aInfo["firstname"] = $FormInput->ProcessInput($_POST["firstname"], "DB_SANITIZE_STRING");
        $aInfo["lastname"] = $FormInput->ProcessInput($_POST["lastname"], "DB_SANITIZE_STRING");
        $aInfo["position"] = $FormInput->ProcessInput($_POST["position"], "DB_SANITIZE_STRING");
        $aInfo["location"] = $FormInput->ProcessInput($_POST["location"], "DB_SANITIZE_STRING");
        
                
        $sMsg = $UserAdmin->SetUser($aInfo, $sUsername);
        
        $_SESSION["sUserAdminMsg"] = $sMsg;
       
        header("Location: ".$_SERVER["PHP_SELF"]);
        exit;

        break;
    case "addnewuser":
        $pageParams["include"]="form_useraccount.inc";
        $pageParams["title"] = "Create New User Account";
        $bIsEdit = false;
        break;
    case "activate":
        $sUsername = $FormInput->ProcessInput($_GET["username"], "ONLY_ALPHA,DB_SANITIZE_STRING");
        $sMsg = $UserAdmin->SetActiveStateByUsername($sUsername, "activate");
        $_SESSION["sUserAdminMsg"] = $sMsg;
       
        header("Location: ".$_SERVER["PHP_SELF"]);
        exit;
        
        break;
    case "deactivate":
        $sUsername = $FormInput->ProcessInput($_GET["username"], "ONLY_ALPHA,DB_SANITIZE_STRING");
        $sMsg = $UserAdmin->SetActiveStateByUsername($sUsername, "deactivate");
        $_SESSION["sUserAdminMsg"] = $sMsg;
        
        header("Location: ".$_SERVER["PHP_SELF"]);
        exit;
    
        break;
    case "resetpassword":
        $sUsername = $FormInput->ProcessInput($_GET["username"], "ONLY_ALPHA,DB_SANITIZE_STRING");
        $sMsg = $UserAdmin->ResetPassword($sUsername);
        $_SESSION["sUserAdminMsg"] = $sMsg;
        
        header("Location: ".$_SERVER["PHP_SELF"]);
        exit;
        break;
    case "":
    default:
        $pageParams["include"]="index.inc";
        break;
}

?>
